<?php
require_once('includes/db.php');
  require_once('header.php');
?>	<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
  <?php
  $where='';
  $tableName='current_opening';
  $orderArray = array('asc','desc');
  $fieldArray = array('status','added_date','name');
  $id = isset($_GET['id']) ? $_GET['id'] : 0;
  $field = ( isset($_GET['field']) && in_array($_GET['field'], $fieldArray) ) ?
           $_GET['field'] : 'added_date';

  $order = ( isset($_GET['order']) && in_array($_GET['order'], $orderArray) ) ?
           $_GET['order'] : 'asc';
  
########### Count total records in users table ##############
  $total_users = CountAll('current_opening');
  
  ########### Count total records in users table ##############

########### PAGING START ###########################

  $rpp = 2;// Record Per Page (offset)
  $total_pages = ceil($total_users / $rpp);
  $currentPage = isset($_GET['page']) ? $_GET['page'] : 1;
  $index = $rpp*($currentPage-1); // limit or from where we have to start fetching

  ############# SORTING START ##########################

  if(isset($_GET['status'])){
    $newStatus = $_GET['status']==0 ? 1 :0;
    $data = array('status'=>$newStatus);
    $flag = updateById($tableName,$data, $id);
	echo success("Successfully Upadated #id $id");
	}
  
  ######### START DELETE ##################
  if(isset($_GET['mode'])) {
    $numRows = deleteby($tableName, $id);
	
    if($numRows == 1){
      echo success("Succefully Deleted #id $id");
    }
  }
  ######### END DELETE  ###################
  
  
?>
<b>LATEST JOB OPENING</b><a href="addjob.php" class="input_setting" style="border-radius: 10px;"><span class="glyphicon glyphicon-plus-sign"></span> Add New</a></br></br>
	<table class="table table-striped">
       <thead>
         <tr>
          
           	
         </tr>
         <tr>
           <td width="5%"><h4><strong>#Id</strong></h4></td>
           <td width="40%"><h4><strong>Description</strong></h4></td>
           <td width="40%"><h4><strong>Technical Skills</strong></h4></td>
           <td width="10%"><h4><strong>Action</strong></h4></td>
           <td width="5%"><h4><strong>Status</strong></h4></td>
         </tr>
        </thead>            	
				<?php
					$result = fetchAll($tableName,$where,'id',$index,$rpp);
					while($data=mysql_fetch_assoc($result)){
						$id=$data['id'];
						$status = getStatus($data['status']);
						$status = "<a style=\"text-decoration:none\" href=\"?id=$id&status=$data[status]&page=$currentPage&field=$field&order=$order\">$status </a>";
  						
				?>				
		<tbody>
			<tr>
				<td><?=$data['id'] ?></td>
						<td>
              
                <h3 class="title-heading color_yellow"><?=$data['tittle'] ?> (<?php $status1 = $data['status'];
				if ($status1 == 1) {echo "Active";
				} else { echo "InActive";
				}
			?>)</h3>
					<ul>
                      <li><?=$data['d1'] ?></li>
                      <li><?=$data['d2'] ?></li>
                      <li><?=$data['d3'] ?></li>
                      <li><?=$data['d4'] ?></li>
                      
					</ul>
              
                </td>
                  <td>  
                    <ul>
                    	<br />
                    	<br />
                    	<br />
                      <li><?=$data['s1'] ?></li>
                      <li><?=$data['s2'] ?></li>
                      <li><?=$data['s3'] ?></li>
                      <li><?=$data['s4'] ?></li>
                    </ul>
                 </td>
       			<td>
                  	<ul>
                  		<div><a onClick="return confirm('Are you sure to delete?')" href="?mode=del&id=<?=$data['id']?>&page=<?=$currentPage?>" class="delete"><span class="glyphicon glyphicon-trash" style="font-size:30px; color: red;"></span></a>&nbsp;&nbsp;&nbsp;</div></br>
                  		<div><a href="editjob.php?id=<?=$data['id']?>" class="edit"><span class="glyphicon glyphicon-edit" style="font-size:30px"></span></a></div>
                  	</ul>
             </td><td align="center"><?=$status?></td>
              </tr>
              
              
             <?php } ?>
             </tbody>
             </table>
                                  <ul class="pagination pagination-lg">

  <li class="disabled"><a href="#">&laquo;</a></li>

<?php
  for ($i=1; $i <= $total_pages ; $i++) {
    if($i==$currentPage) {
?>
  <li class="active"><a href="#"><?=$i?> <span class="sr-only">(current)</span></a></li>

<?php
    } else { //end current page if()
?>
  <li><a href="?page=<?=$i?>"><?=$i?></a></li>
<?php
    } // end else
  }//end for() for paging
?>

  <li><a href="#">&raquo;</a></li>
</ul>

        </div>

        